package com.集合.GradeSort;
import java.util.TreeSet;
public class TreeSetDemo2 {
    public static void main(String[] args) {
        TreeSet<Student2> ts = new TreeSet<Student2>();
        Student2 s1 = new Student2("zhangsan",80,96);
        Student2 s2 = new Student2("lishi",96,80);
        Student2 s3 = new Student2("jack",88,97);
        Student2 s4 = new Student2("tom",80,96);
        ts.add(s1);ts.add(s2);ts.add(s3);ts.add(s4);
        for(Student2 s:ts){
            System.out.println(s);
        }
    }
}
class Student2 implements Comparable<Student2> {
    private String name;
    private int chinese;
    private int math;

    public Student2() {
    }

    public Student2(String name, int chinese, int math) {
        this.name = name;
        this.chinese = chinese;
        this.math = math;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getChinese() {
        return chinese;
    }

    public void setChinese(int chinese) {
        this.chinese = chinese;
    }

    public int getMath() {
        return math;
    }

    public void setMath(int math) {
        this.math = math;
    }

    public String toString() {
        return "姓名:" + name + ", 语文:" + chinese + ", 数学:" + math;
    }

    public int compareTo(Student2 s) {
        int sum1 = this.getChinese()+this.getMath();
        int sum2 = s.getChinese()+s.getMath();
        int num = sum1-sum2;
        int sum3 = num==0 ? this.getName().compareTo(s.getName()):num;

        return sum3;
    }
}
